 <!--调平-->
<template>
  <div class="main">
    <div class="info-container">
      <div class="info-container_body">
        <el-form ref="refFrom" label-position="top" class="demo">
          <!-- <el-form-item label="调平项目">
            <el-select v-model="item.adjustType" placeholder="调平项目">
              <el-option v-for="item in dict.adjust_type" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="数量">
            <el-input-number min="0" integer v-model="item.quantity" />
          </el-form-item>
          <el-form-item label="单价(元)">
            <el-input-number min="0" v-model="price" />
          </el-form-item> -->
          <el-form-item label="调整金额(元)">
            <el-input-number  v-model="item.adjustAmount" />
          </el-form-item>
          <!-- <el-form-item label="应付金额(元)">
            <el-input-number disabled v-model="item.adjustAmount" />
          </el-form-item>
          <el-form-item label="调整后金额(元)">
            <el-input-number disabled v-model="item.adjustAmount" />
          </el-form-item> -->
          <el-form-item label="调平原因">
            <el-input type="textarea" :rows="3" v-model="item.adjustReason" />
          </el-form-item>
          
        </el-form>
      </div>
      <div class="info-container_footer">
        <el-button @click="handleCancel">取消</el-button>
        <el-button type="primary" @click="handleSave">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { adjust } from '@/api/operation/vendorSettlement/index';

export default {
  computed: {
    price: {
      get() {
        return this.item.price / 100;
      },
      set(value) {
        this.item.price = value * 100;
      }
    },
    adjustAmount: {
      get() {
        return (this.item.price * this.item.quantity) / 100;
      },
      set(value) {
        this.item.adjustAmount = value * 100;
      }
    }
  },
  props: {
    data: {}
  },
  data() {
    return {
      proxy: null,
      dict: {},
      item: {
        settlementId: '',
        adjustAmount: 0,
        adjustType: '7',
        price: 0,
        quantity: 0,
        adjustReason: '调平原因'
      }
    };
  },
  mounted() {
    const { proxy } = getCurrentInstance() as ComponentInternalInstance;
    this.proxy = proxy;
    this.dict = toRefs<any>(this.proxy?.useDict('adjust_type'));

    this.init();
  },
  methods: {
    init() {
      this.item.settlementId = this.data.settlementId;
    },

    handleSave() {
      let data = this.item;

      adjust(data).then((res) => {
        if (res.code == 200) {
          //todo:
          this.$emit('hideRight');
        } else {
          ElMessage.error(res.msg);
        }
      });
    },
    handleCancel() {
      this.$emit('hideRight');
    },
    /**
     * 匹配结果
     */
    marchType(value, types) {
      for (let i = 0; i < types.length; i++) {
        let type = types[i];
        if (type.value == value) return type.label;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.main {
  height: 100%;
  .contentFrm {
    padding: 10px;
    background: #f6f7fb;
  }

  .el-input-number__decrease,
  .el-input-number__increase {
    display: none;
  }

  .el-input-number {
    width: 100%;
  }
}
</style>
